<%@ page language="java" pageEncoding="UTF-8"%>
<%@include file="/global/global-head.jsp" %>
<!DOCTYPE html>
<html lang="zh">
<head>
    <title>吉车惠后台管理系统</title>
    <%@include file="/global/global-other.jsp" %>
    <!--/推送通知用-->
    <link rel="stylesheet" type="text/css" href="${ctx}/assets/css/ztstz.css?v=1.1">
    <script type="text/javascript" src="${ctx}/assets/js/ztstz.js?v=3.7"></script>
    <!--/推送通知用-->
    <script type="text/javascript">
        var $android_list = new Object();
        $(function(){
            /*整体选项卡*/
            $('#xzyq').tabs({
                border:false,
                onSelect:function(title){
                    /* alert(title+' is selected'); */
                }
            });
            /*IOS*/
            /*IOS通知内容*/
            $('#iosTz').panel({
                width:'100%',
                height:'250px',
                title: '通知内容<font size="2">（必填）</font>',
                collapsible:false,
                collapsed:false,
            });
            /*IOS推送环境*/
            $('#iosTshj').panel({
                width:'100%',
                height:'131px',
                title: '推送环境<font size="2">（必填）</font>',
                collapsible:false,
                collapsed:false,
            });
            /*ios高级选项*/
            $('#iosGj').panel({
                width:'100%',
                height:'',
                title: '高级设置<font size="2">（选填）</font>',
                headerCls:' background:#06C',
                collapsible:true,
                collapsed:true,

            });
            /*ios自定义参数*/
            $("#iosfive #iosfiveinput").click(function(){
                if($(".iosfivep").css("display")=="none"){
                    $(".iosfivep").show();
                }else{
                    $(".iosfivep").hide();
                }
            });
            /*/IOS*/

            $(".tabs-first").css({"border-left":"1px solid #dddddd"});


            submitAndroidForm = function(){
                $('#android_form').form('submit',{
                    url:'${ctx}/mobile/application/push/notice/ios/insertIos',
                    queryParams:{_m:'insertIos'},
                    onSubmit:function(){
                        if($("#iosfiveinput").get(0).checked){
                            var array = new Array();
                            var row ;
                            var flag = true;
                            $("input[name='iosCustomParameters_key']").each(function(i){
                                if($(this).val() == "" || $("input[name='iosCustomParameters_value']").eq(i).val() == ""){
                                    parent.$.messager.alert("提示",errMsg("参数不能为空"),"error");
                                    flag = false;
                                    return;
                                }
                                row = {
                                    key: $(this).val(),
                                    value: $("input[name='iosCustomParameters_value']").eq(i).val()
                                }
                                array.push(row);
                            })
                            if(!flag){
                                return false;
                            }else{
                                $("#iosCustomParameters").val(JSON.stringify(array));
                            }
                        }
                        if($(this).form('enableValidation').form('validate')){
                            parent.$.messager.progress({
                                text : '推送通知中，请稍后....'
                            });
                            return true;
                        }else{
                            return false;
                        }
                    },
                    success:function(data){
                        var json =  eval("(" +data+ ")");
                        if(statusMsg(json)){
                            parent.$.messager.alert("提示","发送成功！","info",function(){
                                location= getUrl(location.href);//刷新当前页面
                            });
                        }
                        parent.$.messager.progress('close');
                    },
                    error:function(data){
                        parent.$.messager.progress('close');
                    }
                });
            };

            $('#appId').combobox({
                onChange : function(){
                    var v = $("#appId").combobox("getText") ;
                    var v1 = $("#appId").combobox("getValue") ;
                    $("#appName").val(v);
                    $("#adr_title").val(v);

                    $("#appKeyTemp").combobox("setValue",v1) ;
                    var v3 = $("#appKeyTemp").combobox("getText") ;
                    $("#appKey").val(v3);
                }
            });

            $('#sendTime').datebox().datebox('calendar').calendar({
                validator: function(date){
                    var now = new Date();
                    var d1 = new Date(now.getFullYear(), now.getMonth(), now.getDate());
                    return date >= d1;
                }
            });

            $('#objectContent_device').click(function(){
                $android_list.appUserDeviceInit();
            })

            $('#objectContent_account').click(function(){
                $android_list.appUserAccountInit();
            })

            //清空
            clearSendObject = function(id){
                $("#appUserId").val("");
                $("#"+id).val("");
            }
        });


        var viewDialog ;
        //app用户 device
        $android_list.appUserDeviceInit = function(){
            viewDialog = parent.$.dialog({
                title: '<i class="fa fa-th-large"></i><span class="dialog-title">&nbsp;app用户<span>',
                href: '${ctx}/mobile/application/push/notice/ios/insertIos?_m=appUsersDeviceSearchInit&r='+Math.random(),
                width: 900,
                height: 620,
                modal: true,
                onClose : function() {
                    $(this).dialog('destroy');
                },
                buttons: [{
                    text:'<i class="fa fa-floppy-o" aria-hidden="true"></i>&nbsp;选 择',
                    width:'70px',
                    handler: function(){
                        var json =  viewDialog.find('iframe').get(0).contentWindow.choose();
                        var appUserId = [];
                        var deviceId = [];
                        for(var i = 0; i < json.length; i++ ){
                            var row =  json[i];
                            appUserId.push(row.appUserId);
                            deviceId.push(row.deviceId);
                        }

                        //app用户
                        var appuser = $("#appUserId").val()
                        if(appuser == ""){
                            $("#appUserId").val(appUserId.join(","));
                        }else{
                            appuser = appuser + "," +appUserId.join(",");
                            $('#appUserId').val(appuser);
                        }

                        //app device
                        var device = $('#objectContent_device').val();
                        if(device == ""){
                            $('#objectContent_device').val(deviceId.join(","));
                        }else{
                            device = device + "," +deviceId.join(",");
                            $('#objectContent_device').val(device);
                        }

                    }
                },{
                    text:'<i class="fa fa-reply" aria-hidden="true"></i>&nbsp;关 闭',
                    width:'70px',
                    handler: function(){
                        viewDialog.dialog('destroy');
                    }
                }]
            });
        }


        $android_list.appUserAccountInit = function(){
            viewDialog = parent.$.dialog({
                title: '<i class="fa fa-th-large"></i><span class="dialog-title">&nbsp;app用户<span>',
                href: '${ctx}/mobile/application/push/notice/ios/insertIos?_m=appUsersAccountSearchInit&r='+Math.random(),
                width: 900,
                height: 620,
                modal: true,
                onClose : function() {
                    $(this).dialog('destroy');
                },
                buttons: [{
                    text:'<i class="fa fa-floppy-o" aria-hidden="true"></i>&nbsp;选 择',
                    width:'70px',
                    handler: function(){
                        var json =  viewDialog.find('iframe').get(0).contentWindow.choose();
                        var appUserId = [];
                        var accounts = [];
                        for(var i = 0; i < json.length; i++ ){
                            var row =  json[i];
                            appUserId.push(row.appUserId);
                            accounts.push(row.account);
                        }

                        //app用户
                        var appuser = $("#appUserId").val()
                        if(appuser == ""){
                            $("#appUserId").val(appUserId.join(","));
                        }else{
                            appuser = appuser + "," +appUserId.join(",");
                            $('#appUserId').val(appuser);
                        }

                        //app device
                        var account = $('#objectContent_account').val();
                        if(account == ""){
                            $('#objectContent_account').val(accounts.join(","));
                        }else{
                            account = account + "," +accounts.join(",");
                            $('#objectContent_account').val(account);
                        }

                    }
                },{
                    text:'<i class="fa fa-reply" aria-hidden="true"></i>&nbsp;关 闭',
                    width:'70px',
                    handler: function(){
                        viewDialog.dialog('destroy');
                    }
                }]
            });
        }
    </script>
    <style>
        .panel {
            margin-bottom: 20px;
            background-color: #ffffff;
            border: 1px solid transparent;
            border-radius: 4px;
            -webkit-box-shadow: 0 1px 1px rgba(0, 0, 0, 0.05);
            box-shadow: 0 1px 1px rgba(0, 0, 0, 0.05);
        }
        .panel-header{ background:#0682e1;color:#000;}
        .panel-title{ color: #ffffff;
            font-size: 16px;
            padding-left: 15px;
        }

        /*aa*/
        ul,li {
            margin: 0;
            padding: 0;
            list-style: none;
        }
    </style>
</head>
<body>
<div class="easyui-layout" data-options="fit:true">
    <div data-options="region:'center',border:false">
        <div style="width:900px;height:auto;padding:15px;border:0px;">
            <!----------------------------------------------------------------------------------Android---------------------------------------------------------------------------------->
            <form  role="form" method="POST" name="android_form" id="android_form" class="easyui-form form form-horizontal" data-options="novalidate:true">
                <input type="hidden" id="appName" name="appName" value=""/>
                <input type="hidden" id="appKey" name="appKey" value=""/>
                <input type="hidden" id="appUserId" name="appUserId" value=""/>
                <input type="hidden" id="iosCustomParameters" name="iosCustomParameters" value=""/>
                <!--通知内容-->
                <div id="iosTz" style="padding:10px;">
                    <div>移动应用：</div>
                    <div class="col-sm-12" style=" margin-bottom:20px;">
                        <input type="text" id="appId" name="appId" value="" class="form-control easyui-combobox" style="width:100%;height:34px;line-height:34px;" data-options="valueField: 'id',textField: 'appName',url:'${ctx}/api/mobileapplication/list',editable:false" required="required">
                    </div>
                    <div class="col-sm-12" style=" margin-bottom:20px;display:none;">
                        <input type="text" id="appKeyTemp" name="appKeyTemp" value="" class="form-control easyui-combobox" style="width:100%;height:34px;line-height:34px;" data-options="valueField: 'id',textField: 'appKey',url:'${ctx}/api/mobileapplication/list',editable:false">
                    </div>
                    <div style="display:none;">
                        <div>通知标题：<span id="titlelen" class=" text-right" style=" float:right;">0/20</span></div>
                        <div class="col-sm-12" style=" margin-bottom:20px;">
                            <input type="text" autocomplete="on" id="adr_title" onkeyup="title_len();" onclick="title_len();" name="title" value="" class="form-control easyui-validatebox" maxlength="20" placeholder="车行天下">
                        </div>
                    </div>
                    <div>通知内容：<span id="adrcontentlen" class=" text-right" style=" float:right;">0/60</span></div>
                    <div class="col-sm-12">
                        <textarea id="adr_content" onkeyup="adrContent_len();" onclick="adrContent_len();" class="form-control easyui-validatebox"  autocomplete="on" ng-trim="true" maxlength="60" name="content" rows="3" placeholder="请输入通知内容" required="required"></textarea>
                    </div>
                </div>
                <!--字数限制-->
                <script language="javascript" type="text/javascript">
                    //标题
                    function title_len(){
                        var value = $('#adr_title').val().length;
                        if(value == 20){
                            var string = "<span style=\"color:#FF0000\">"+value+"/20</span>";
                        }else{
                            var string = "<span style=\"color:#FF0000\">"+value+"</span>/20";
                        }
                        $('#titlelen').html(string);
                    }
                    //内容
                    function adrContent_len(){
                        var value = $('#adr_content').val().length;
                        if(value == 60){
                            var string = "<span style=\"color:#FF0000\">"+value+"/60</span>";
                        }else{
                            var string = "<span style=\"color:#FF0000\">"+value+"</span>/60";
                        }
                        $('#adrcontentlen').html(string);
                    }
                </script>
                <!--/字数限制-->

                <!--ios推送环境-->
                <div id="iosTshj" style="padding:10px;">
                    <ul id="iosTabfirst"  style=" padding:15px 9%;">
                        <div style=" float:left; padding:20px 0; margin-right:3%;"><label></label></div>
                        <li id="schjxz">
                            <label class="checkbox-inline">
                                <input type="radio" name="pushSetting"  value="PRODUCT" checked > 生产环境
                            </label>
                        </li>
                        <li id="kfhjxz">
                            <label class="checkbox-inline">
                                <input type="radio" name="pushSetting"  value="DEV"> 开发环境
                            </label>
                        </li>
                    </ul>
                </div>
                <!--ios高级设置-->
                <div id="iosGj" style="padding:15px;">
                    <!--点击通知后操作-->
                    <div style="width:99%; border-bottom:#CCC solid 1px; padding:10px 0;">点击通知后操作：</div>

                    <ul class="iostabsame" style=" padding:15px 9%;">
                        <div style=" float:left; padding:15px 0; margin-right:3%;"><label>后续操作：</label></div>
                        <li>
                            <label class="checkbox-inline">
                                <input type="radio" name="iosBackgroundOperation"  value="APPLICATION" checked > 打开应用
                            </label>
                        </li>
                    </ul>

                    <!--ios自定义参数-->
                    <div style=" float:left;width:99%; padding:0 9%;">
                        <div style=" float:left; padding:15px 0; margin-right:3%;"><label>自定义参数：</label></div>

                        <div id="iosfive" style="float:left; padding:5px 14px;">
                            <label class="checkbox-inline" >
                                <input type="checkbox" name="iosfiveinput"  value="1" id="iosfiveinput"  > key-value（最多五个）：
                            </label>
                        </div>
                    </div>
                    <div class="iosfivep">
                        <table id="iosFive" style="width:100%;">
                            <tr>
                                <th class="iosfivetitle">key</th>
                                <th class="iosfivetitle">value</th>
                                <th class="iosfivesc"></th>
                            </tr>
                            <tr>
                                <td class="iosfivebody"><input type="text" name="iosCustomParameters_key" class="form-control"></td>
                                <td class="iosfivebody"><input type="text" name="iosCustomParameters_value" class="form-control"></td>
                                <td class=""></td>
                            </tr>
                        </table>
                        <div class="iosfiveadd" onclick="javascript:addIosCurrentRow();" >+添加Key-Value</div>

                        <script>
                            function addIosCurrentRow()
                            {
                                var a = $('#iosFive').children().children().length;
                                if(a<6){
                                    var trcomp="<tr><td class='iosfivebody'><input type='text' name='iosCustomParameters_key' class='form-control'/></td><td class='iosfivebody'><input type='text' name='iosCustomParameters_value' class='form-control'></td><td class='fivesctxt'><a href='javascript:;' onclick='deleteIosCurrentRow(this);'><font>删除</font></a></td></tr>";
                                    $("#iosFive tr:last-child").after(trcomp);
                                }
                            }


                            function deleteIosCurrentRow(obj)
                            {
                                var tr=obj.parentNode.parentNode;
                                var tbody=tr.parentNode;
                                tbody.removeChild(tr);
                            };
                            /*点几次数限制*/


                        </script>

                    </div>
                    <!--/ios自定义参数-->
                    <!--发送对象及时间-->
                    <div style="width:99%; border-bottom:#CCC solid 1px; padding:10px 0; float:left; margin-top:20px;">发送对象及时间：</div>
                    <!--推送环境-->
                    <div class="ioscontentfirst ioscontentin" style="clear:both; padding:0px;">
                        <!--发送对象-->
                        <ul id="iosTabsecond"  style=" padding:15px 9%;">
                            <div style=" float:left; padding:10px 0; margin-right:3%;"><label>发送对象：</label></div>
                            <li id="kfhjxzh">
                                <label class="checkbox-inline">
                                    <input type="radio" name="sendObject"  value="ALL" checked > 所有人
                                </label>
                            </li>
                            <li id="zdzdxz">
                                <label class="checkbox-inline">
                                    <input id="rdozd" type="radio" name="sendObject"  value="DEVICE" > 指定终端
                                </label>
                            </li>
                            <li>
                                <label class="checkbox-inline">
                                    <input type="radio" name="sendObject"  value="ACCOUNT"> 指定账号
                                </label>
                            </li>
                        </ul>
                        <!--所有人-->
                        <div class="ioscontentsecond" style="clear:both;padding:0px;"></div>
                        <!--指定终端-->
                        <div class="ioscontentsecond">
                            <div role="tabpanel" class="tab-pane well active"  ng-show="data.operationType == 2"><input type="text" id="objectContent_device" name="objectContent_device" class="form-control " style="width:90%;cursor: pointer;" data-options="editable:false" ng-model="" placeholder="请输入DeviceID，多个终端用逗号分隔"/><span style="float:right; margin: -25px 5% 0 0;"><a href="#" onclick="clearSendObject('objectContent_device')">清空</a></span></div>
                        </div>
                        <!--指定账号-->
                        <div class="ioscontentsecond">
                            <div role="tabpanel" class="tab-pane well active"  ng-show="data.operationType == 2"><input type="text" id="objectContent_account" name="objectContent_account" class="form-control" style="width:90%;cursor: pointer;" data-options="editable:false" ng-model="" placeholder="请输入账号，多个账号用逗号分隔"/><span style="float:right; margin: -25px 5% 0 0;"><a href="#" onclick="clearSendObject('objectContent_account')">清空</a></span></div>
                        </div>
                        <!--/发送对象-->
                    </div>
                    <!--/推送环境-->
                    <!--发送时间-->
                    <div class="clearfix"></div>
                    <ul id="iosTabthird"  style=" padding:15px 9%;">
                        <div style=" float:left; padding:8px 0; margin-right:3%;"><label>发送时间：</label></div>
                        <li>
                            <label class="checkbox-inline">
                                <input type="radio" name="sendWay"  value="1" checked > 立即发送
                            </label>
                        </li>
                        <li>
                            <label class="checkbox-inline">
                                <input type="radio" name="sendWay"  value="2"> 定时发送
                            </label>
                        </li>

                    </ul>
                    <!--立即发送-->
                    <div class="ioscontentthird" style="clear:both;padding:0px;"></div>
                    <!--定时发送-->
                    <div class="ioscontentthird">
                        <div role="tabpanel" class="tab-pane well active"  ng-show="data.operationType == 2">
                            <input id="sendTime" name="sendTime" class="form-control easyui-datetimebox" value="" style="width:200px;height:35px;" data-options="editable:false">
                        </div>
                    </div>
                    <!--/发送时间-->
                    <!--离线保存-->
                    <div class="clearfix"></div>
                    <ul id="iosTabforth"  style=" padding:15px 9%;">
                        <div style=" float:left; padding:8px 0; margin-right:3%;"><label>离线保存：</label></div>
                        <li>
                            <label class="checkbox-inline">
                                <input type="radio" name="offlineSave"  value="2"> 不保存
                            </label>
                        </li>
                        <li>
                            <label class="checkbox-inline">
                                <input type="radio" name="offlineSave"  value="1" checked > 保存
                            </label>
                        </li>

                    </ul>
                    <!--不保存-->
                    <div class="ioscontentforth" style="clear:both;padding:0px;"></div>
                    <!--保存-->
                    <div class="ioscontentforth ioscontentin4">
                        <div class="well col-sm-12">保存 <input type="number" ng-model="data.timeout" id="saveHours" name="saveHours" value="72" max="72" min="1" placeholder="72" required="required" class="easyui-validatebox ng-pristine ng-invalid ng-invalid-number ng-valid-max ng-valid-min"/> 小时，该时段之后再上线的用户将收不到推送 <span ng-show="" class="alert-danger ng-hide">至少保存1小时</span> <span ng-show="" class="alert-danger ng-hide">最多只能保存72小时</span></div>
                    </div>
                    <!--/离线保存-->
                    <!--/发送对象及时间-->
                    <!--/点击通知后操作-->
                    <div class="clearfix"></div>
                    <ul class="tabsamea" style="padding:15px 9%;">
                        <div style=" float:left; padding:8px 0; margin-right:3%;"><label>系统消息：</label></div>
                        <li>
                            <label class="checkbox-inline">
                                <input type="radio" name="isSendSystemMessage"  value="1" checked > 是
                            </label>
                        </li>
                        <li>
                            <label class="checkbox-inline">
                                <input type="radio" name="isSendSystemMessage"  value="2" > 否
                            </label>
                        </li>
                    </ul>
                </div>

                <div class="col-sm-10" style="padding-bottom:50px;">
                    <button type="button" onclick="submitAndroidForm()" class="btn btn-info btn-squared" style="width:120px">
                        确定发送
                    </button>
                </div>
            </form>
        </div>
    </div>
</div>
</body>
</html>